package com.xiaobai.frame.controller;


import com.xiaobai.common.utils.result.Result;
import com.xiaobai.frame.entity.ClientDetails;
import com.xiaobai.frame.entity.DTO.PageDTO;
import com.xiaobai.frame.service.IClientDetailsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 第三方登录数据表 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-06-29
 */
@RestController
@RequestMapping("/client-details")
@AllArgsConstructor
public class ClientDetailsController {

    private IClientDetailsService iClientDetailsService;

    @GetMapping("run/{appid}")
    @Operation(summary = "获取code",
        description = "传入的appid是通过认证服务器发放的",
        parameters = {
            @Parameter(name = "appid", required = true, in = ParameterIn.PATH)
        })
    public Result run(@PathVariable("appid") String appid) {
        return iClientDetailsService.run(appid);
    }

    @PostMapping("get-token")
    @Operation(summary = "通过code获取token")
    @Parameters({
        @Parameter(name = "appid", required=true, description = "系统的appid"),
        @Parameter(name = "appSecret", required = true, description = "该系统的密钥"),
        @Parameter(name = "code", required = true, description = "获取到的临时密钥")
    })
    public Result getToken(@RequestParam("appid") String appid,
                           @RequestParam("appSecret") String appSecret,
                           @RequestParam("code") String code) {
        return iClientDetailsService.getToken(appid, appSecret, code);
    }

    @GetMapping("list")
    @Operation(summary = "查询所有三方授权系统")
    public Result list(@RequestBody PageDTO pageDTO) {
        return iClientDetailsService.listData(pageDTO);
    }

    @GetMapping("get/{id}")
    @Operation(summary = "查询单个数据的详细信息")
    public Result getOne(@PathVariable("id") String id) {
        return iClientDetailsService.getOneData(id);
    }

    @PostMapping
    @Operation(summary = "新增数据")
    public Result addData(@RequestBody ClientDetails clientDetails) {
        return iClientDetailsService.addData(clientDetails);
    }

    @PutMapping
    @Operation(summary = "修改数据")
    public Result updateData(@RequestBody ClientDetails clientDetails) {
        return iClientDetailsService.updateData(clientDetails);
    }

    @DeleteMapping
    @Operation(summary = "删除数据")
    public Result deleteData(Long[] ids) {
        return iClientDetailsService.deleteData(ids);
    }


}
